package com.gimi.cloud.jimi.dao.dao.userInfo;


import com.gimi.cloud.jimi.common.utils.StringUtil;

/**
 * Dao层注解批量处理类
 * @author zhoufuhang
 *
 */

public class UserAppInformationDaoProvider {

	public String insertUserInformationSql(long userId, int appIdentify, String appVersion, double latitude, double longitude,
			String address, String ip, String uniqueInformation, String idfa, String unitType, String operators,
			String channelId, String appId, int userAction, int saveType, String ipLocation){
			String sql="insert into rd_user_app_information(user_id,app_identify,app_version,latitude,longitude,address,ip,ip_location,unique_information,idfa,unit_type,operators,channel_id,app_id,add_time,user_action,save_type,latitude2,longitude3) "
					+ "values(':userId',':appIdentify',':appVersion',':latitude',':longitude',':address',':ip',':ipLocation',':uniqueInformation',':idfa',':unitType',':operators',':channelId',':appId',now(),':userAction',':saveType',ROUND(:latitude2,2),ROUND(:longitude3,3))";
			sql = sql.replace(":userId", userId + "");
			sql = sql.replace(":appIdentify", appIdentify + "");
			sql = sql.replace(":appVersion", appVersion + "");
			sql = sql.replace(":latitude", latitude + "");
			sql = sql.replace(":longitude", longitude + "");
			sql = sql.replace(":latitude2", latitude + "");
			sql = sql.replace(":longitude3", longitude + "");
			if(StringUtil.isNotBlank(address) && address.length() %2 == 0){//不为空且长度为偶数
				if(address.substring(0, address.length() / 2).equals(address.substring(address.length() / 2))){//如果对半相等，则重复，去掉重复
					address = address.substring(0, address.length() / 2);//截取一半
				}
			}
			if (address.indexOf("'") != -1) {
				address = address.replace("'", "’");
			}
			sql = sql.replace(":address", address);
			sql = sql.replace(":ipLocation", ipLocation);
			sql = sql.replace(":ip", ip);
//			sql = sql.replace("ipLocation", LocationUtils.getAddressByIp(ip,false));
			sql = sql.replace(":uniqueInformation", uniqueInformation);
			sql = sql.replace(":idfa", idfa);
			sql = sql.replace(":unitType", unitType);
			sql = sql.replace(":operators", operators);
			sql = sql.replace(":channelId", channelId);
			sql = sql.replace(":appId", appId);
			sql = sql.replace(":userAction", userAction + "");
			sql = sql.replace(":saveType", saveType + "");
		return sql;
	}

}
